# %% Prepare ----
rm(list = ls())

library(plotly)

source("X28_draw_help.R")
source("X28_plot_functions.R")

save.type <- "PPT"
# save.type <- "PNG"
# save.type <- "SVG"


# PDAC ----
# 2.4mg/kg
pdac24 <- filter_plotset(tumor = "PDAC", dose = "2.4")
(pswim <- ggswim(pdac24,  "PDAC (2.4 mg/kg)"))
(pspider <- ggspider(pdac24,  "PDAC (2.4 mg/kg)"))
(pspider2 <- ggspider2(pdac24,  "PDAC (2.4 mg/kg)"))
(pwaterfall <- ggwaterfall(pdac24,  "PDAC (2.4 mg/kg)"))
save_plots("PDAC24", save.type = save.type)

ggplotly(pswim)
ggplotly(pspider)
ggplotly(pwaterfall)

# 2.0 mg/kg
pdac20 <- filter_plotset(tumor = "PDAC", dose = "2.0")
(pswim <- ggswim(pdac20,  "PDAC (2.0 mg/kg)"))
(pspider <- ggspider(pdac20,  "PDAC (2.0 mg/kg)"))
(pwaterfall <- ggwaterfall(pdac20,  "PDAC (2.0 mg/kg)"))
save_plots("PDAC20", save.type = save.type)


# CC ----
# 2.4mg/kg
# debugonce(ggspider)
cc24 <- filter_plotset(tumor = "CC", dose = "2.4")
(pswim <- ggswim(cc24,  "CC (2.4 mg/kg)"))
(pspider <- ggspider(cc24,  "CC (2.4 mg/kg)"))
# (pspider <- ggspider2(cc24,  "CC (2.4 mg/kg)"))
(pwaterfall <- ggwaterfall(cc24,  "CC (2.4 mg/kg)"))
save_plots("CC24", save.type = save.type)

# 2.0 mg/kg
cc20 <- filter_plotset(tumor = "CC", dose = "2.0")
(pswim <- ggswim(cc20,  "CC (2.0 mg/kg)"))
(pspider <- ggspider(cc20,  "CC (2.0 mg/kg)"))
(pwaterfall <- ggwaterfall(cc20,  "CC (2.0 mg/kg)"))
save_plots("CC20", save.type = save.type)


# OC ----
# 2.4mg/kg
oc24 <- filter_plotset(tumor = "OC", dose = "2.4")
(pswim <- ggswim(oc24,  "OC (2.4 mg/kg)"))
(pspider <- ggspider(oc24,  "OC (2.4 mg/kg)"))
(pwaterfall <- ggwaterfall(oc24,  "OC (2.4 mg/kg)"))
save_plots("OC24", save.type = save.type)

# 2.0 mg/kg
oc20 <- filter_plotset(tumor = "OC", dose = "2.0")
(pswim <- ggswim(oc20,  "OC (2.0 mg/kg)"))
(pspider <- ggspider(oc20,  "OC (2.0 mg/kg)"))
(pwaterfall <- ggwaterfall(oc20,  "OC (2.0 mg/kg)"))
save_plots("OC20", save.type = save.type)


# Dose-escalation part ----
escalation <- patient.info |> 
  filter(isDoseEsca == TRUE)
(pswim <- ggswim(escalation,  "Dose-escalation part"))
(pspider <- ggspider(escalation,  "Dose-escalation part"))
(pwaterfall <- ggwaterfall(escalation,  "Dose-escalation part"))
save_plots("Escalation", save.type = save.type)


# All patients ----
(pswim <- ggswim(patient.info,  "OC (2.0 mg/kg)"))
(pspider <- ggspider(patient.info,  "OC (2.0 mg/kg)"))
(pwaterfall <- ggwaterfall(patient.info,  "OC (2.0 mg/kg)"))
